﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Athena.model;
using Athena.basedal;
using Athena.Idal;

//项目名称：Athena标准开发框架
//版本：0.0.1
//开发团队成员：周庆 王露 张婷婷 陈祚松 张梦丽 艾美珍 胡凯雨 陈兰兰 夏萍萍 康文洋 易传佳
//模块及代码页功能描述：用户获取动作、资源等信息
//最后修改时间:2018-01-11
//修改日志：

namespace Athena.bll
{
    public class UserInfo
    {
        public static List<action> getUserAllAction(string username, string owner = "")//获取指定用户的特定类型和属主的动作列表,会含有重复项
        {
            List<action> rr = new List<action>();

            List<role> rolelist = IocModule.GetEntity<IroleEx>().getUserRoles(username);
            if (rolelist.Count > 0)
            {
                IroleActionEx _roleActionEx = IocModule.GetEntity<IroleActionEx>();
                foreach (var e in rolelist)
                {
                    rr.AddRange(_roleActionEx.getRoleAllAction(e.id, owner));
                }
                rr = rr.Where((x, i) => rr.FindIndex(z => z.id == x.id) == i).ToList();//Lambda表达式去重  
            }
            return rr;
        }
        public static List<action> getUserAction(string username, int type, string owner = "")//获取指定用户的特定类型和属主的动作列表,会含有重复项
        {
            List<action> rr = new List<action>();
            List<role> rolelist = IocModule.GetEntity<IuserRoleEx>().getRole(username);
            if (rolelist.Count > 0)
            {
               IroleActionEx _roleActionEx=  IocModule.GetEntity<IroleActionEx>();
                foreach (var e in rolelist)
                {
                    rr.AddRange(_roleActionEx.getRoleAction(e.id, type, owner));
                }
                rr = rr.Where((x, i) => rr.FindIndex(z => z.id == x.id) == i).ToList();//Lambda表达式去重  
            }
            return rr;
        }
        public static List<resource> getUserResource(string username, int type, string owner = "")//获取指定用户的特定类型和属主的资源列表
        {
            List<resource> rr = new List<resource>();
            List<role> rolelist = IocModule.GetEntity<IroleEx>().getUserRoles(username);
            if (rolelist.Count > 0)
            {
                IroleResourceEx _roleResourceEx = IocModule.GetEntity<IroleResourceEx>();
                foreach (var e in rolelist)
                {
                    rr.AddRange(_roleResourceEx.getRoleResource(e.id, type, owner));
                }
                rr = rr.Where((x, i) => rr.FindIndex(z => z.id == x.id) == i).ToList();//Lambda表达式去重  
            }
            return rr;
        }
        public static List<resource> getUserAllResource(string username, string owner = "")//获取指定用户的特定类型和属主的资源列表
        {
            List<resource> rr = new List<resource>();
            List<role> rolelist = IocModule.GetEntity<IroleEx>().getUserRoles(username);
            if (rolelist.Count > 0)
            {
                IroleResourceEx _roleResourceEx = IocModule.GetEntity<IroleResourceEx>();
                foreach (var e in rolelist)
                {
                    rr.AddRange(_roleResourceEx.getRoleAllResource(e.id, owner));
                }
                rr = rr.Where((x, i) => rr.FindIndex(z => z.id == x.id) == i).ToList();//Lambda表达式去重  
            }
            return rr;
        }
    }
}
